package com.pyue.eam.app.controller;

import com.pyue.eam.app.api.entity.AppTabbarEntity;
import com.pyue.eam.app.service.AppTabbarService;
import com.pyue.eam.common.core.util.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 底部导航
 *
 * @date 2023-06-07 16:32:35
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/appTabbar")
@Tag(description = "appTabbar", name = "底部导航")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class AppTabbarController {
    private final AppTabbarService tabbarService;

    /**
     * 查询导航列表
     *
     * @return R
     */
    @Operation(summary = "查询导航列表", description = "查询导航列表")
    @GetMapping("/list")
    public R<List<AppTabbarEntity>> list(Integer typeId) {
        return R.okList(tabbarService.lambdaQuery()
                .eq(AppTabbarEntity::getTypeId, typeId)
                .orderByAsc(AppTabbarEntity::getOrderNum)
                .list());
    }

    @Operation(summary = "更新导航", description = "更新导航")
    @PutMapping
    public R update(@RequestBody List<AppTabbarEntity> tabbarEntityList) {
        return R.ok(tabbarService.updateTabbar(tabbarEntityList));
    }
}
